/**
 * @作者 Lucas
 * @创建时间 2020/5/17 19:50
 */
package com.lucas.springboot_restful_api.api.v1;

import com.lucas.springboot_restful_api.core.UnifyResponse;
import com.lucas.springboot_restful_api.core.interceptors.ScopeLevel;
import com.lucas.springboot_restful_api.dto.UserLoginDTO;
import com.lucas.springboot_restful_api.dto.UserRegisterDTO;
import com.lucas.springboot_restful_api.exception.http.NotFoundException;
import com.lucas.springboot_restful_api.exception.http.ParameterException;
import com.lucas.springboot_restful_api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Validated
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public UnifyResponse login(@RequestBody @Validated UserLoginDTO dto) throws Exception {
        switch (dto.getType()) {
            case USER_Email:
                return userService.loginByEmail(dto);
            case USER_WX:
                break;
            default:
                throw new NotFoundException(10003);
        }
        throw new ParameterException(10006);
    }

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public UnifyResponse register(@RequestBody @Validated UserRegisterDTO dto) throws Exception {
        switch (dto.getType()) {
            case USER_Email:
                return userService.registerByEmail(dto);
            case USER_WX:
                break;
        }
        throw new ParameterException(10006);
    }

    @RequestMapping(value = "/level_4", method = RequestMethod.POST)
    @ScopeLevel(value = 4)
    public UnifyResponse level4() throws Exception {
        return new UnifyResponse();
    }

    @RequestMapping(value = "/level_8", method = RequestMethod.POST)
    @ScopeLevel(value = 8)
    public UnifyResponse level8() throws Exception {
        return new UnifyResponse();
    }

    @RequestMapping(value = "/level_16", method = RequestMethod.POST)
    @ScopeLevel(value = 16)
    public UnifyResponse level16() throws Exception {
        return new UnifyResponse();
    }

}
